package org.lq.shopping.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.log4j.Logger;
import org.lq.shopping.dao.ShopPmethodDao;
import org.lq.shopping.entity.ShopPmethod;
import org.lq.shopping.test.LogTest;
import org.lq.shopping.util.DruidUtil;
/**
 * 
 * @author 赵得福
 *
 * @时间 2018年9月26日
 * Shopping_LQ
 */
public class ShopPmethodDaoimpl implements ShopPmethodDao{
	Logger log = Logger.getLogger(ShopPmethodDaoimpl.class);
	
	
	QueryRunner qr=new QueryRunner(DruidUtil.getDataSource());
	@Override
	public int add(ShopPmethod t) {
		int num = 0;
		String sql="insert into shop_pmethod(payid,pmethod,enable) values(pmethod_seq.nextval,?,?)";
		log.debug(sql);
		log.info("添加付款方式");
		try {
			num=qr.execute(sql, t.getPmethod(),t.getEnable());
		} catch (SQLException e) {
			e.printStackTrace();
			log.error("错误：添加付款方式");
		}
		return num;
	}

	@Override
	public int delete(int id) {
		int num = 0;
		String sql="delete shop_pmethod where payid = ?";
		log.debug(sql);
		log.info("删除付款方式");
		try {
			num=qr.execute(sql, id);
		} catch (SQLException e) {
			e.printStackTrace();
			log.error("错误：删除付款方式");
		}
		return num;
	}

	@Override
	public int update(ShopPmethod t) {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * 查询全部
	 * 付款方式表
	 */
	@Override
	public List<ShopPmethod> findAll() {
		List<ShopPmethod> list = new ArrayList<>();
		String sql="select * from shop_pmethod";
		log.debug(sql);
		log.info("查询全部付款方式");
		try {
			list=qr.query(sql,new BeanListHandler<>(ShopPmethod.class));
		} catch (SQLException e) {
			e.printStackTrace();
			log.error("错误：查询全部付款方式");
		}
		return list;
	}

	@Override
	public ShopPmethod findById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<ShopPmethod> LikeColumnByValue(String columName, Object value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<ShopPmethod> findPage(int pageIndex, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

}
